<!--出库管理模块-->
<template>
  <div  style="position: relative;">
    <mmTable ref="mmTable" :mmColumns="columns" :getUrl="url" :updateUrl="updateUrl" :delUrl="delUrl"
             :form="form" :formData="formData" v-on:formDataChange="formDataChange"
             :searchFormData="searchFormData" :searchForm="searchForm" :showColAction="false"
             :modalWidth="800">
      <Form slot="searchForm" ref="searchForm" :model="searchFormData" inline :label-width="70"  style="float: left">
        <FormItem label="用户名" prop="">
          <Input v-model="searchFormData.name" type="text" placeholder="" />
        </FormItem>
      </Form>
      <!--编辑添加模态框-->
      <Form  slot="editForm" :label-width="100" :model="formData" inline ref="editForm" :rules="formValidate">

        <Row>
          <Col :span="12">
          <FormItem label="入库编号" prop="inbillcode" style="width:300px">
            <Input v-model="formData.inbillcode" type="text" @on-enter="keydown" />
          </FormItem>
          </Col>
          <Col :span="12">
          <FormItem label="库存" prop="surplus" style="width:300px">
            <Input v-model="formData.surplus" readonly />
          </FormItem>
          </Col>
        </Row>
        <Row>
          <Col :span="12">
          <FormItem label="货品" prop="materialname" style="width:300px">
            <Input v-model="formData.materialname" type="text" readonly/>
          </FormItem>
          </Col>
          <Col :span="12  ">
          <FormItem label="仓库" prop="warehousename" style="width:300px">
            <Input v-model="formData.warehousename" type="text" readonly/>
          </FormItem>
          </Col>
        </Row>
        <Row>
          <Col :span="12">
          <FormItem label="出库重量" prop="weight" style="width:300px">
            <InputNumber style="width:200px"  :max="max"  v-model="formData.weight"/>
          </FormItem>
          </Col>
        </Row>
      </Form>
    </mmTable>
  </div>
</template>
<!--关联后台原料，供货商，仓库平台-->
<script>
import warehouseSel from '../components/select/warehouseSelect.vue'
import materialSel from '../components/select/materialSelect.vue'
import compaySel from '../components/select/compaySelect.vue'
import mmTable from '../components/mmtable/mmtable.vue'
import { getInPlanByCar,getWarehousebyCode ,delData} from '@/api/busi'
export default {
  components: {
    mmTable,
    warehouseSel,
    materialSel,
    compaySel
  },
  data () {
    /*显示列表*/
    return {
        max:0,
      columns: [
        { title: '出库编号', key: 'billcode', width: 200, align: 'center' },
        { title: '入库编号', key: 'inbillcode', width: 200, align: 'center' },
        { title: '出库时间', key: 'createtime', width: 200, align: 'center' },
        { title: '出库重量', key: 'weight', width: 200, align: 'center' },
        { title: '出库人', key: 'creatorname', width: 200, align: 'center' },
        { title: '货品', key: 'materialname', width: 200, align: 'center' },
        { title: '仓库', key: 'warehousename', width: 200, align: 'center' },
        {
          title: "操作",
          key: "action",
          width: 200,
          align: "center",
          render: (h, params) => {
            return h(
              "Button",
              {
                props: {
                  type: "error",
                  size: "small"
                },
                style: {
                  marginRight: "5px"
                },
                on: {
                  click: () => {
                    this.delete(params.row);
                  }
                }
              },
              "删除"
            )
          }
        }
      ],
      /*链接后台*/
      url: '/deliver/getList',
      updateUrl: '/deliver/Save',
      delUrl: '/deliver/Delete',
      form: {},
      formValidate: {
      },
      searchForm: {},
      searchFormData: {
        code: '',
        name: ''
      },
      /*后台传的数据*/
      formData: {
        inbillcode: '',
        weight:0,
        company: '',
        warehouse: '',
        id: '',
        materials: ''
      },
      searchFormData: {
        name: ''
      },
      searchForm: {}
    }
  },
  mounted () {
    this.form = this.$refs.editForm
    this.searchForm = this.$refs.searchForm
  },
  /*方法*/
  methods: {
    formDataChange (data) {
      this.formData = data
    },
    keydown(v){
      let that = this
      if (this.formData.inbillcode) {
        getWarehousebyCode({rkcode:this.formData.inbillcode}).then(res=>{
          if (res.data.code == 200) {
            if (res.data.data) {
              that.formData = res.data.data;
              that.max =that.formData.surplus;
            }
          }
        })
      }

    },
    delete(row){
      this.$Modal.confirm({
        title: "确认删除",
        content: "确认要删除记录?",
        onOk: () => {
          delData({id:row.id,weight:row.weight,inbillcode:row.inbillcode}).then(res => {
            let data =res.data
            if (data.code == 200) {
              this.$Message.success("删除成功");
              this.$refs.mmTable.init()
            }
          });
        }
      });
    }
  }
}
</script>

<style>

</style>
